package com.wangyk.rabbitmqconsole.config;

import com.wangyk.rabbitmqconsole.filter.AddUserIdFilter;
import com.wangyk.rabbitmqconsole.filter.KeywordHandleFilter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 过滤器的配置
 * @Author: wangyk
 * @CreateDate: 2018/11/27$ 8:53$
 * @UpdateUser: wangyk
 * @UpdateDate: 2018/11/27$ 8:53$
 * @UpdateRemark:
 * @Version: 1.0
 */
@Configuration
public class FilterConfig
{
    /**
     * 日志打印
     */
    private Logger logger = LoggerFactory.getLogger(FilterConfig.class);

    /**
     * 注册关键词过滤器
     */
    @Bean
    public FilterRegistrationBean registerKeywordHandleFilter()
    {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new KeywordHandleFilter());
        registrationBean.setName("KeywordHandleFilter");
        registrationBean.addUrlPatterns("/*");
        registrationBean.setOrder(1);//是设置该过滤器执行的顺序。SpringBoot会根据order从小到大的顺序执行。
        return registrationBean;
    }

    /**
     * 注册添加用户ID的过滤器
     */
    @Bean
    public FilterRegistrationBean registerAddUserIdFilter()
    {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setFilter(new AddUserIdFilter());
        registrationBean.setName("AddUserIdFilter");
        //拦截所有的请求
        registrationBean.addUrlPatterns("/*");
        //是设置该过滤器执行的顺序。SpringBoot会根据order从小到大的顺序执行。
        registrationBean.setOrder(0);
        return registrationBean;
    }
}
